{include file="common/head"}
<head>
  <title>学费设置</title>
<link    rel="stylesheet"    href="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jodit/3.24.2/jodit.es2018.min.js"></script>    
    <link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
    <script src="/static/flatpickr/flatpickr.js"></script>

  <style type="text/css">
      #top{background: initial;border-bottom:1px solid rgba(0,0,0,0.1);max-width: 1000px;}
    .mb-3{margin-bottom:5px!important;}
    form{position:fixed; top:5%;left:10%;  padding: 10px 20px;display: none;z-index: 20;background: #fff;width:800px;}    
  </style>    
</head>
<body style="max-width: 1000px;">
    <div class="" style="padding:20px;">
      <h2><a href='/index.php/cat/fee_setup'>收款项目设置</a> <a href='/index.php/refund/config'>红包设置</a> 优惠券设置</h2>
      <table class="table table-sm table-striped" border="1">
        <thead class="table-info">
          <th>序号</th>
          <th>优惠券名称</th>
          <th>使用规则说明</th>
          <th>金额</th>
          <th>可用条件<br/>(订单最小金额)</th>
          <th>状态<br/>(1:开放,2:关闭)</th>
          <th>图片</th>
          <th>起始时间</th>
          <th>结束时间</th>
          <th>
            <button class="btn btn-sm btn-primary" id="new_item"><span class="bi-plus"></span></button>
          </th>
        </thead>
        <tbody>
          {foreach $data as $k=>$v}
          <tr class="fee_item" > 
            <td class="_id" style="padding: 0 10px;">{$v['id']}</td>
            <td class="_name">{$v['name']}</td>
            <td class="_desc long_field">{$v['desc']}</td>
            <td class="_money">{$v['money']}</td>
            <td class="_order_money">{$v['order_money']}</td>
            <td class="_status">{$v['status']}</td>
            <td >
              <img class="goods_image" src="{$v['image']}" style="width:70px;border:1px solid #ccc;" />
            </td>            
            <td class="_stime">{$v['stime']}</td>
            <td class="_etime">{$v['etime']}</td>

            <td>
              <button class="btn btn-sm btn-secondary"><span class="bi-pencil"></span></button>
             </td>
          </tr>
          {/foreach}

        </tbody>
      </table>

<!--  <button class="btn btn-primary" id="new_item">
        <span class="bi-plus">新增收款项</span>
      </button> -->

      <!-- <button type="button" class="btn btn-info" id="save">保存设定</button>     -->
      <div id="mask"></div>
      <br/>
      <form method="post" enctype="multipart/form-data" action="/index.php/refund/voucher_list" style="">
        <h3 class="text-center"><c id="edit_name"></c>优惠券<input type="hidden" id="id" name="id" value="" /></h3>
        <br/>
        <div class="mb-3 row">
          <div class="col-2"><label for="title" class="form-label">项目名称:</label></div>
          <div class="col-10"><input type="text" class="form-control" id="name" name="name" value="" placeholder="" /></div>
        </div>

        <div class="mb-3 row">
          <div class="col-2"><label for="desc" class="form-label">规则说明:</label></div>
          <div class="col-10">
            <textarea id="desc" name="desc" class="form-control"></textarea>
          </div>
        </div>

        <div class="mb-3 row">
          <div class="col-2"><label for="money" class="form-label">抵扣金额:</label></div>
          <div class="col-10"><input type="number" class="form-control" id="money" name="money" value="" placeholder="" /></div>
        </div>
        <div class="mb-3 row">
          <div class="col-2"><label for="order_money" class="form-label">订单最小金额:</label></div>
          <div class="col-10"><input type="number" class="form-control" id="order_money" name="order_money" value="" placeholder="" /></div>
        </div>

        <div class="mb-3 row">
          <div class="col-2"><label for="desc" class="form-label">有效时间:</label></div>
          <div class="col-10 row">
            <div class="col">
              <label for="stime" class="form-label text-primary">开始时间:</label>
              <input type="text" class="form-control" id="stime" name="stime" value="" style="width:200px;display: initial;" placeholder="" />
            </div>
            <div class="col">
              <label for="etime" class="form-label text-primary">结束时间:</label>
              <input type="text" class="form-control" id="etime" name="etime" value="" style="width:200px;display: initial;" placeholder="" />
          </div>
          </div>
        </div>        
        <br/>
        <div class="mb-3 row">
          <div class="col-2"><label for="file" class="form-label">上传图片:</label></div>
          <div class="col-10">
            <img src="" id="img" alt="image" style="width: 140px;border:1px solid #ccc;"/>
            <input id="file" type="file"  name="file" />
          </div>
        </div>  

        <div class="mb-3 row">
          <div class="col-2">
            <label for="status" class="form-label">是否启用:</label>
          </div>
          <div class="col-10">
            <input type="radio" class="form-check-input" id="radio1" name="status" value="1" checked /> 
            <label class="form-check-label" for="radio1">启用</label>
            <input type="radio" class="form-check-input" id="radio2" name="status" value="2" />
            <label class="form-check-label" for="radio2">停用</label>
         </div>  
         </div>      

        <button type="submit" class="btn btn-primary" onclick="return dosave()" style="display: inline;">提交保存</button>
      </form>





<!--       <div style="margin:20px 0;font-size:larger;color:#red;">
        说明： 两个金额都设置为0，系统会删除此项目！
      </div> -->
    </div>

<script type="text/javascript">
    var editor = Jodit.make('#desc',{
      toolbarButtonSize: 'small',
      language: 'zh_cn',
    });

    flatpickr("#stime,#etime", {});
    $("#stime,#etime").flatpickr({
        enableTime: true,
        dateFormat: "Y-m-d H:i:s",
    });    

    function dosave(){
      if(!$("#name").val() || !$("#money").val()){
        layer.msg('设置错误，请检查设置再提交!');return false;
      }
      return true;
    }

$(document).ready(function(){
    $("#mask").on('click',function(){
      $("form").hide();
      $(this).hide();
    })

    $(".goods_image").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          title:'',
          closeBtn: 0, //不显示关闭按钮
         // anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='width:100%'>"
        });
    })
  
  //新增项目
  $("#new_item").on('click',function(){
    $("#edit_name").text('新增');
    $("#id").val('');
    $("#name").val('');
    $("#desc").val('');
    $("#money").val('');
    $("#order_money").val('');
    editor.value='';
    $("#mask").show();
    $("form").show();
  })

  $(".btn-secondary").on('click',function(){
    $("#edit_name").text('编辑');
    var el=$(this).parents('tr');
    var id=el.find('._id').text(); 

    $("#id").val(id);
    $("#name").val(el.find('._name').text());
    //$("#desc").text(el.find('._desc').text());
    editor.value=el.find('._desc').text();
    $("#money").val(el.find('._money').text());
    $("#order_money").val(el.find('._order_money').text());
    $("#img").attr('src',el.find('img').attr('src'));
    $("#stime").val(el.find('._stime').text());
    $("#etime").val(el.find('._etime').text());
$("#mask").show();
    $("form").show();

  })



})


</script>


</body>
</html>
